package com.wc.alorithm_blue_bridge._DFS.串变换;

import java.util.Scanner;

/**
 * @Author congege
 * @Description 串变换
 * https://www.lanqiao.cn/probleks/757/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/27-21:29
 */
public class Main {
    static String s;
    static String t;
    static int n;
    static int k;
    static int[][] operators;
    static boolean[] flg;
    static boolean ans = false;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = Integer.parseInt(sc.nextLine());
        s = sc.nextLine();
        t = sc.nextLine();
        k = Integer.parseInt(sc.nextLine());

        operators = new int[k][3];
        flg = new boolean[k];
        for (int i = 0; i < k; i++) {
            operators[i][0] = Integer.parseInt(sc.next());
            operators[i][1] = Integer.parseInt(sc.next());
            operators[i][2] = Integer.parseInt(sc.next());
        }
        dfs(0, s.toCharArray());
        if (ans) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
//        System.out.println(cnt);
    }

    public static void dfs(int floor, char[] chs) {
        if (floor == k) {
            if (new String(chs).equals(t)) {
                ans = true;
            }

            return;
        }
        for (int i = 0; i < k; i++) {
            if (!flg[i]) {
                flg[i] = true;
                char[] tmp1 = new char[n];
                char[] tmp2 = new char[n];
                System.arraycopy(chs, 0, tmp1, 0, n);
                System.arraycopy(chs, 0, tmp2, 0, n);

                // 执行
                operate(operators[i], tmp1);
                dfs(floor + 1, tmp1);
                // 不执行
                dfs(floor + 1, tmp2);
                flg[i] = false;
            }
        }
    }

    public static void operate(int[] operator, char[] chs) {
        if (operator[0] == 2) {
            char c = chs[operator[1]];
            chs[operator[1]] = chs[operator[2]];
            chs[operator[2]] = c;
        } else {
            chs[operator[1]] += operator[2];
            if (chs[operator[1]] > '9') {
                chs[operator[1]] -= 10;
            }
        }
    }
}
